package com.cbw.blog.service.impl;

import com.cbw.blog.entity.Comment;
import com.cbw.blog.entity.Statistic;
import com.cbw.blog.mapper.CommentMapper;
import com.cbw.blog.mapper.StatisticMapper;
import com.cbw.blog.service.ICommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author baomidou
 * @since 2022-09-05
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements ICommentService {

    @Resource
    StatisticMapper statisticMapper;
    @Override
    public void pushComment(Comment comment) {
        this.save(comment);
        Statistic statistic = statisticMapper.selectById(comment.getArticleId());
        statistic.setCommentsNum(statistic.getCommentsNum()+1);
        statisticMapper.updateById(statistic);
    }
}
